#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>

using namespace std;

const int MaxN = 1000000 + 5;

int n, a, b;
int f[MaxN];

bool Can[MaxN];

int Find(int x) {
    int i, j, k;
    j = x; while (j != f[j]) j = f[j];
    i = x;
    while (i != j) {
        k = i;
        i = f[i];
        f[k] = j;
    }
    return j;
}

void Esun(int x, int y) {
    if (Can[x]) Can[y] = true;
    else Can[x] = true;
    f[x] = y;
}

int main()
{
#ifdef hai
    //freopen("in.txt", "r", stdin);
#endif
    scanf("%d", &n);
    for (int i = 1; i <= 10005; ++i) f[i] = i;
    memset(Can, 0, sizeof(Can));
    for (int i = 1; i <= n; ++i) {
        scanf("%d%d", &a, &b);
        int Fa = Find(a), Fb = Find(b);
        if (Fa > Fb) swap(Fa, Fb);
        if (Fa == Fb) Can[Fa] = true;
        else Esun(Fa, Fb);
    }
    int Ans = 0;
    while (Can[Ans + 1]) ++Ans;
    printf("%d\n", Ans);
    return 0;
}
